package com.kmvc.message.activity;

//package com.kmvc.message;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.kmvc.message.R;
import com.kmvc.message.tools.WebService;
import com.kmvc.ui.IphoneTitleBarActivity;

public class MessageFanKui extends IphoneTitleBarActivity implements OnClickListener {
	EditText editText, editText2;
	String Result = "";
	Handler handler = new Handler();

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.messagefankui);
		setTitle(R.string.feedback_suggest);
	    setLeftButton(R.string.goback, null);
	    
		Button submit = (Button) findViewById(R.id.submit);
		editText = (EditText) findViewById(R.id.editText1);
		editText2 = (EditText) findViewById(R.id.editText2);

		submit.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.titleback:
			this.finish();
			break;
		case R.id.submit:
			Send(editText.getText().toString(), editText2.getText().toString());
		default:
			break;
		}
	}

	Runnable runnable = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			if (Result.equals("OK")) {
				Toast.makeText(MessageFanKui.this, "反馈成功,感谢您的参与",
						Toast.LENGTH_LONG).show();
			} else {
				Toast.makeText(MessageFanKui.this, "反馈失败", Toast.LENGTH_LONG)
						.show();
			}
		}
	};

	private void Send(final String string, final String string2) {
		if (!string.trim().equals("") && !string2.trim().equals("")) {
			new Thread() {
				public void run() {
					try {
						Result = WebService.Fankui(string, string2) + "";
					} catch (Exception e) {

					}
					handler.post(runnable);
				}
			}.start();
		}else {
			Toast.makeText(MessageFanKui.this, "请将信息填写完整,谢谢",
					Toast.LENGTH_LONG).show();
		}
		
	}
}
